package com.gitee.wsl.func.transform

import com.gitee.wsl.func.Function

/**
 * Defines a functor interface implemented by classes that transform one
 * object into another.
 *
 *
 * A `Transformer` converts the input object to the output object.
 * The input object SHOULD be left unchanged.
 * Transformers are typically used for type conversions, or extracting data
 * from an object.
 *
 *
 *
 * Standard implementations of common transformers are provided by
 * [TransformerUtils]. These include method invocation, returning a constant,
 * cloning and returning the string value.
 *
 *
 * @param <T> the type of the input to the function.
 * @param <R> the type of the result of the function.
 * @since 1.0
</R></T> */

interface Transformer<T, R> : Function<T, R> {
     override fun apply(t: T): R {
        return transform(t)
    }

    /**
     * Transforms the input object into some output object.
     *
     *
     * The input object SHOULD be left unchanged.
     *
     *
     * @param input  the object to be transformed, should be left unchanged
     * @return a transformed object
     * @throws ClassCastException (runtime) if the input is the wrong class
     * @throws IllegalArgumentException (runtime) if the input is invalid
     * @throws FunctorException (runtime) if the transform cannot be completed
     */
    fun transform(input: T): R

    companion object
}